home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-02-07 | 2.7 KB | 114 lines | [TEXT/MPS ] |
- (*
- recvBytes(count) -- Return count bytes from the serial port, in ASCII, with one byte per item in the
- returned string.
-
- To compile and link this file using Macintosh Programmer's Workshop,
-
- pascal -w recvBytes.p
- link -m ENTRYPOINT -o HyperCommands -rt XFCN=7037 -sn Main=recvBytes ∂
- recvBytes.p.o "{MPW}"Libraries:interface.o "{MPW}"Libraries:Libraries:HyperXLib.o
-
- © Copyright 1989 by Apple Computer, Inc.
-
- Initial coding 12/89 by Harry R. Chesley.
- *)
-
- {$R-}
-
- {$S recvBytes } { Segment name must be the same as the command name. }
-
- unit DummyUnit;
-
- interface
-
- uses MemTypes, QuickDraw, OSIntf, HyperXCmd;
-
- procedure EntryPoint(paramPtr: XCmdPtr);
-
- implementation
-
- procedure recvBytes(paramPtr: XCmdPtr); forward;
-
- procedure EntryPoint(paramPtr: XCmdPtr);
-
- begin
- recvBytes(paramPtr);
- end;
-
- procedure recvBytes(paramPtr: XCmdPtr);
-
- var readHandle: Handle;
- readCount: longInt;
- readCountStr: Str255;
- l, l2: longInt;
- p: Ptr;
- s: Str255;
-
- procedure Fail(errMsg: Str255); { set theResult and quit }
- begin
- paramPtr^.returnValue := PasToZero(paramPtr,errMsg);
- exit(recvBytes);
- end;
-
- {$I SPortUtil.inc}
-
- begin
- if paramPtr^.paramCount <> 1 then Fail('parameter count is not 1');
-
- ZeroToPas(paramPtr,paramPtr^.params[1]^,readCountStr); { First parameter is count to read. }
- readCount := StrToNum(paramPtr,readCountStr);
- if readCount < 0 then Fail('invalid count');
-
- SetUpSPortGlobals;
- EnsureOpenPort;
-
- { Create the input handle. }
- readHandle := NewHandle(readCount);
- HLock(readHandle);
- { Read, read, read... }
- if readCount > 0 then
- begin
- l := readCount;
- if FSRead(ThisSPort.portInDev,l,readHandle^) <> noErr then
- begin
- DisposHandle(readHandle);
- Fail('FSRead failed');
- end;
- { Shrink the handle if we didn't get everything (paranoid programing; this should be impossible). }
- if l <> readCount then SetHandleSize(readHandle,l);
- end
- else l := 0;
- { Should we strip? }
- if ThisSPort.stripIncoming then
- begin
- { If so, rip dem bits off. }
- p := readHandle^;
- for l2 := 1 to l do
- begin
- p^ := BAND(p^,$7F);
- p := pointer(ord4(p)+1);
- end;
- end;
- { Convert to a string. }
- paramPtr^.returnValue := NewHandle(0);
- p := readHandle^;
- for l2 := 1 to l do
- begin
- LongToStr(paramPtr,BAND(p^,$FF),s);
- s := Concat(s,',');
- if PtrAndHand(pointer(ord4(@s)+1),paramPtr^.returnValue,length(s)) <> noErr then
- begin
- DisposHandle(readHandle);
- DisposHandle(paramPtr^.returnValue);
- Fail('PtrAndHand failed');
- end;
- p := pointer(ord4(p)+1);
- end;
- p := pointer(ord4(paramPtr^.returnValue^)+GetHandleSize(paramPtr^.returnValue)-1);
- if p <> paramPtr^.returnValue^ then p^ := 0;
- HUnlock(readHandle);
- DisposHandle(readHandle);
- end;
-
- end.
-